package myerror

type businessError struct {
	httpCode     int    // http 状态码
	businessCode int    // 业务码
	message      string // 错误描述
	stackError   error  // 含有堆栈的错误信息
	isAlert      bool   // 是否告警通知
}

type BusinessError interface {
	//WidthError 设置错误信息
	WidthError(err error) BusinessError
	//	WithAlert 设置告警信息
	WithAlert() BusinessError
	// BusinessCode 获取业务码
	BusinessCode() int
	//HttpCode	获取状态码
	HttpCode() int
	//Message	获取错误信息
	Message() string
	//StackError	获取堆栈信息
	StackError() error
	// IsAlert	是否设置告警
	IsAlert() bool
}

// https://segmentfault.com/q/1010000023319314/a-1020000023331436
//var _ BusinessError = (*businessError)(nil)

func Error(httpCode, businessCode int, message string) BusinessError {
	return &businessError{
		httpCode:     httpCode,
		businessCode: businessCode,
		message:      message,
		isAlert:      false,
	}
}

func (b businessError) WidthError(err error) BusinessError {
	//TODO implement me
	panic("implement me")
}

func (b businessError) WithAlert() BusinessError {
	b.isAlert = true
	return b
}

func (b businessError) BusinessCode() int {
	return b.businessCode
}

func (b businessError) HttpCode() int {
	return b.httpCode
}

func (b businessError) Message() string {
	return b.message
}

func (b businessError) StackError() error {
	return b.stackError
}

func (b businessError) IsAlert() bool {
	return b.isAlert
}
